package com.yodawnla.katana.Hud;

import org.anddev.andengine.entity.Entity;
import org.anddev.andengine.entity.sprite.Sprite;

import com.yodawnla.katana.Player;
import com.yodawnla.katana.Hud.HudMgr.Hud;
import com.yodawnla.katana.system.SE;
import com.yodawnla.katana.system.Tex;
import com.yodawnla.lib.YoActivity;
import com.yodawnla.lib.util.widget.YoButton;
import com.yodawnla.lib.util.widget.YoHudMgr;

public class EndHud extends AHud
{
	public static EndHud getInstance()
	{
		if (instance == null)
			instance = new EndHud();
		return instance;
	}
	
	static EndHud instance;
	
	YoActivity mBase = YoActivity.getBaseActivity();
	
	Player mPlayer = Player.getInstance();
	
	public interface ITalkHudListener
	{
		public void onHudInitFinish();
	}

	Entity layer;
	EndHud()
	{
		super(Hud.End);
		hide();
		layer = YoHudMgr.getInstance().getHudLayer(mName);
		
		YoButton bg = new YoButton(YoHudMgr.getInstance().getHud(), 0, 0, 800, 480, mBase.getTexture(Tex.End))
		{
			public void onClickedEvent()
			{
				hide();
				mBase.toScene("StageScene");
			}
		};
		layer.attachChild(bg);
		
	}
	
	Sprite mPlayerSprite;
	
	public void show()
	{
		if (mPlayerSprite != null)
			mPlayerSprite.setVisible(false);
		
		super.show();
		
		mBase.runOnUpdateThread(new Runnable()
		{
			public void run()
			{
				if (mPlayerSprite != null)
				{
					mPlayerSprite.setPosition(-10000, -10000);
					mPlayerSprite.setVisible(false);
					mPlayerSprite.clearEntityModifiers();
					mPlayerSprite.detachSelf();
				}
				
				mPlayerSprite = new Sprite(0, 0, 500, 477, mBase.getTexture(Tex.Char+mPlayer.getCharType()).deepCopy());
				layer.attachChild(mPlayerSprite);
				mBase.playSound(SE.Yooo);
			}
		});
	}
}